# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 锁的练习.py
Author: kij
Create Date: 2021/3/18
-------------------------------------------------
"""
import os
from multiprocessing import Process, Lock, RLock
import time


class MyProcess(Process):
	def __init__(self, lock):
		super().__init__()
		self.lock = lock

	def run(self):
		self.lock.acquire()
		print("锁的练习{}".format(os.getpid()))
		time.sleep(2)
		print('睡醒了')
		self.lock.release()


if __name__ == "__main__":
	# 普通锁
	lock = Lock()
	process = []
	for i in range(3):
		my_process = MyProcess(lock)
		process.append(my_process)
		my_process.start()
	for item in process:
		item.join()


# 递归锁 可以反复拿到，拿一次次数加一，放掉后剪一，直到为0时候其他进程才能拿到

class MyProcessRLock(Process):
	def __init__(self):
		print("练习递归锁")

	def run(self):
		print("启动了")


if __name__ == '__main__':
	print()
